class ProductCategory < ActiveRecord::Base
  acts_as_tree :order=>"name", :dependent => :nullify

  belongs_to :user
  
  has_many :products, :dependent => :destroy

  has_many :restaurant_product_category_memberships
  has_many :restaurants, :through => :restaurant_product_category_memberships

  validates_uniqueness_of :name
  
  def has_subcategories?
    !children.empty?
  end
  
  def selectable_parent_categories
    categories = (ProductCategory::find(:all) - [self])
    categories.collect {|c| [ c.name, c.id ] }
  end
end
